<template>
	<view class="details">
		<view class="swipers">
			<swiper  @change="getcurrent" class="swiperBanner" indicator-active-color="#E8271B" :indicator-dots="false" :autoplay="true" :interval="3000"
			 :duration="1000" :circular="true">
				<swiper-item v-for="(item,index) in bannerList" :key='index'>
					<view class="swiper-item">
						<image :src="item" mode="scaleToFill"></image>
					</view>
				</swiper-item>

			</swiper>
			<view class="indicatorown">
				{{currentNum}}/{{total}}
			</view>
			<view class="backheader">
				
				<!-- #ifdef H5 -->
				<view class="back">
					<image src="../../static/images/back_icon.png" mode=""></image>
					
				</view>
				<!-- #endif -->
				
				<!-- <view class="shoppingCar">
					<image src="../../static/images/cart.png" mode=""></image>
					<image src="../../static/images/share.png" mode=""></image>
				</view> -->
			</view>
		</view>
		<view class="seckillImg" v-if="commodityInfo.specialStatus == 1">
			<image src="../../static/images/special_label_3.png" mode="widthFix"></image>
			<view class="leftPriceBox">
				<view class="top">
					<view class="priceBox">
						<view class="price">
							￥<text>{{price}}</text>
						</view>
					</view>
					<view class="people">
						即将恢复至原价￥{{commodityInfo.originalPrice || 0}}
					</view>
				</view>
				<view class="bottomBox">
					特卖价
				</view>
			</view>
			
		
		</view>
		<view class="titles">
			<view class="pirceBox">
				<view class="price" v-if="commodityInfo.specialStatus != 1">
					￥<text>{{price}}</text>
				</view>
				<view class="price" v-if="commodityInfo.specialStatus == 1">
					<text class="title">天天好省</text>
					<text class="title">低价特卖</text>
				</view>
				<view class="salesNum">
					总销量{{sale}}
				</view>
			</view>
			<view class="title">
				{{title}}
			</view>
		</view>
		
		<view class="severBox">
			<view class="send">
				发货 <text>{{startSend}}</text> <text class="express">快递：{{expressNum}}</text>
			</view>
			<view >
				服务
				 <text v-for="(item,index) in serviceIdListNum" :key="index" v-if="item != ''">
				 {{serviceIdList[item-1]}}
				 </text>
			</view>
			<view class="param" @tap="openSheet">
				<view >
					参数 <text>品牌，货号...</text>
				</view> <image src="../../static/images/more_icon.png" mode="scaleToFill"></image>
			</view>
		</view>
		
		<view class="evaluate">
			<view class="title">
				<view >
					商品评价（{{evaluate.num}}）
				</view>
				<view class="readAll" @tap="gocomment(evaluate)">
					查看全部
					<image  src="../../static/images/more_icon.png" mode="scaleToFill"></image>
				</view>
			</view>
			<view class="firstEvaluate">
				<view class="userinfo" v-if="firstEvaluate.userName">
					<image :src="firstEvaluate.userLogo || '../../static/images/user.png'" mode="scaleToFill"></image>{{firstEvaluate.userName}}
				</view>
				<view class="evaluateInfo" v-if="firstEvaluate.userName">
					{{firstEvaluate.comment}}
				</view>
			
				<view class="evaluateInfo" v-else>
					暂无评价
				</view>
			</view>
		</view>
		<view class="shop">
			<view class="shopName">
				<image src="../../static/images/shop_icon_1.png" mode="scaleToFill"></image>
				<text>{{storeName}}</text>
			</view>
			<view class="goshop" @tap="goShop">
				进入店铺
			</view>
		</view>
		<view class="commodityInfo">
			<view class="commodityHeader">
				商品详情
			</view>
			<view class="commodityInfoContent">
				<image v-for="(item,index) in commodityInfoList" :key="index" :src="item" mode="widthFix"></image>
			</view>
		</view>
		
		<view class="bottom">
			<view class="kefu" @tap="goChat()">
				<image src="../../static/images/service_icon.png" mode="scaleToFill"></image>
				<view>
					客服
				</view>
			</view>
			<view class="collect" @tap="collectCommodity">
				<image v-if="!isCollect" src="../../static/images/collect_icon.png" mode="scaleToFill"></image>
				<image v-if="isCollect" src="../../static/images/collect_icon_1.png" mode="scaleToFill"></image>
				<view>
					收藏
				</view>
			</view>
			<view class="btns addCar" @tap="showCommodityInfo(0)">
				加入购物车
			</view>
			<view class="btns buyNow" @tap="showBuyCommodity">
				立即购买
			</view>
			
		</view>
		
	
		<sheet v-if="isShowBottom" @closeBottom = "closeSheet"></sheet>
		<commodity-info v-if="isShowCommodityInfo" @closeBottom = "closeSheet"></commodity-info>
		<buy-commodity v-if="isShowBuyCommodity" @closeBottom = "closeSheet"></buy-commodity>
	</view>
</template>

<script>
	import sheet from '../../components/bbh-sheet/bottomSheet.vue'
	import commodityInfo from '../../components/bbh-sheet/commodityInfo.vue'
	import buyCommodity from '../../components/bbh-sheet/buyCommodity.vue'
	export default {
		components:{
			sheet,
			commodityInfo,
			buyCommodity
		},
		data() {
			return {
				isShowBottom:false,
				isShowCommodityInfo:false,
				isShowBuyCommodity:false,
				bannerList: [],
				commodityInfoList:[],
				total:1,
				currentNum:1,
				price:0,
				sale:0,
				title:'',
				startSend:"",
				expressNum:0,
				storeName:"",
				evaluate:{},
				serviceIdListNum:[],
				serviceIdList:["提供发票","包修服务","退换承诺"],
				param:{},
				firstEvaluate:{},
				storeId:"",
				isCollect:false,
				id:"",
				productAttributeCategoryId:"",
				commodityInfo:{},
				isLogin:false
			}
		},
		onLoad(e) {
			if(uni.getStorageSync('userId') != ""){
					this.isLogin = true
			}
			this.id = e.id
			this.getInfoData()
		},
		methods:{
			getcurrent(num){
				this.currentNum = num.detail.current + 1;
			},
			//获取数据
			getInfoData(){
				let data = {
					id: this.id
				}
				this.$http.post(this.$http.baseUrl + '/api/v1.0/app/product/findProductInfoById',data,res=>{
					this.commodityInfo = res.data.data;
					this.productAttributeCategoryId = res.data.data.productAttributeCategoryId
					this.storeId = res.data.data.storeId
					this.bannerList = res.data.data.pic.split(',');
					this.commodityInfoList = res.data.data.albumPics.split(',')
					this.total = this.bannerList.length;
					this.price = res.data.data.price;
					this.sale = res.data.data.sale;
					this.title = res.data.data.name;
					this.startSend = res.data.data.shipAddress;
					this.storeName = res.data.data.storeName;
					this.expressNum = res.data.data.freight;
					this.evaluate.num = res.data.data.commentCount;
					if(res.data.data.serviceIds != ""){
						this.serviceIdListNum = res.data.data.serviceIds.split(',');
					}
					this.param.brandName = res.data.data.brandName
					this.param.productSn = res.data.data.productSn;
					if(res.data.data.commentResponse != null){
						this.firstEvaluate.comment = res.data.data.commentResponse.comment
						this.firstEvaluate.userName = res.data.data.commentResponse.userName
						this.firstEvaluate.userLogo = res.data.data.commentResponse.userLogo
					}
					
					
					this.getIsCollect()
				})
			},
			//获取是否收藏
			getIsCollect(){
				let data = {
					productId:this.id
				}
				this.$http.post('/api/v1.0/collect/findProductCollect',data,res=>{
					if(res.data.data == 0){
						this.isCollect = false
					}else if(res.data.data == 1){
						this.isCollect = true
					}
				})
			},
			openSheet(){
				this.isShowBottom = true;
			},
			// 关闭弹窗
			closeSheet(){
				this.isShowBottom = false;
				this.isShowCommodityInfo = false;
				this.isShowBuyCommodity = false;
			},
			//跳转商品
			goShop(item){
				uni.navigateTo({
					url:'../shop/shop?shopId=' + this.storeId
				})
			},
			collectCommodity(){
				if(this.isLogin == false){
					uni.navigateTo({
						url: '../login/login'
					});
					return
				}
				let data = {
					productId:this.id,
					productName:this.title,
					productPrice:this.price,
					productSale:this.sale,
					storeId:this.storeId,
					storeName:this.storeName,
					icon: this.bannerList[0],
				}
				if(this.isCollect == false){
					this.$http.post('/api/v1.0/collect/SaveProduct',data,res=>{
						if(res.data.data == 1){
							this.isCollect = true;
							uni.showToast({
								title:"收藏成功",
								icon:"none"
							})
						}else{
							uni.showToast({
								title:"收藏失败",
								icon:"none"
							})
						}
					})
				}else{
					this.$http.post('/api/v1.0/collect/DeleteProduct',data,res=>{
						if(res.data.data == 1){
							this.isCollect = false;
							uni.showToast({
								title:"取消收藏成功",
								icon:"none"
							})
						}else{
							uni.showToast({
								title:"取消收藏失败",
								icon:"none"
							})
						}
					})
				}
			},
			//加入购物车弹窗
			showCommodityInfo(type){
				if(this.isLogin == false){
					uni.navigateTo({
						url: '../login/login'
					});
					return
				}
				this.isShowCommodityInfo = true
			},
			//立即购买弹窗
			showBuyCommodity(type){
				if(this.isLogin == false){
					uni.navigateTo({
						url: '../login/login'
					});
					return
				}
				this.isShowBuyCommodity = true
			},
			//查看全部评价
			gocomment(){
				console.log(this.commodityInfo)
				uni.navigateTo({
					url:"../evaluate/comment?id=" + this.commodityInfo.id
				})
				
			},
			goChat(){
				// #ifdef MP-TOUTIAO
					uni.showToast({
						title:'暂不支持此功能~',
						icon:'none'
					})
					return false
				// #endif
				
				if(this.isLogin == false){
					uni.navigateTo({
						url:'../login/login'
					})
					return
				}
				
				uni.navigateTo({
					url:'../chat/chat?name='+ this.storeName + '&storeId=' + this.storeId
				})
			}
		},
		
	}
</script>

<style lang="scss">
	.details {
		background-color: #f7f7f7;
		.swipers{
			position: relative;
			.indicatorown {
				position: absolute;
				width: 104upx;
				height: 39upx;
				line-height: 39upx;
				color: #fff;
				background-color: #000;
				border-radius: 5upx 20upx 5upx 20upx;
				text-align: center;
				right: 30upx;
				bottom: 50upx;
				font-size: 22upx;
				transform: translate;
			}
			.swiperBanner{
				height: 750upx;
				.swiper-item{
					width: 100%;
					height: 100%;
				}
				image{
					width: 100%;
					height: 100%;
				}
			}
			
			.backheader{
				position: absolute;
				width: 100%;
				top: 20upx;
				padding-left: 28upx;
				box-sizing: border-box;
				display: flex;
				align-items: center;
				justify-content: flex-end;
				/*#ifdef H5*/
			
					justify-content: space-between;
				
				/* #endif*/
				
				// justify-content: end;
				image{
					width: 64upx;
					height: 64upx;
				}
				.shoppingCar{
				
					margin-right: 28upx;
					image{
						margin-left: 20upx;
					}
				}
			}
		}
		.seckillImg{
			width: 100%;
			height: 120upx;
			padding-left: 40upx;
			padding-top: 10upx;
			box-sizing: border-box;
			position: relative;
			display: flex;
			justify-content: space-between;
			image{
				position: absolute;
				top: 0;
				left: 0;
				right: 0;
				bottom: 0;
				width: 100%;
				height: 100%;
				z-index: 1;
			}
			.leftPriceBox{
				position: relative;
				z-index: 9;
				.top{
					display: flex;
					justify-content: flex-start;
					align-items: center;
					.priceBox{
						display: flex;
						justify-content: flex-start;
						align-items: center;
						.price{
							font-size: 28upx;
							font-weight: bold;
							color: #fff;
							margin-right: 10upx;
							text{
								font-size: 36upx;
							}
						}
						.oldprice{
							font-size: 22upx;
							text-decoration: line-through;
							color: #fff;
						}
					}
					.people{
						background-color: #fff;
						color: #F8AD1B;
						border-radius: 20upx;
						font-size: 22upx;
						padding: 5upx 12upx;
						margin-left: 10upx;
					}
				}
				.bottomBox{
					color: #fff;
					font-size: 22upx;
					letter-spacing:10upx
				}
			}
			
		}
		.titles{
			background-color: #fff;
			.pirceBox{
				width: 100%;
				display: flex;
				justify-content: space-between;
				align-items: center;
				box-sizing: border-box;
				padding: 30upx;
				margin-bottom: 20upx;
				.price{
					color: #f63810;
					font-size: 24upx;
					text{
						font-size: 32upx;
						&.title{
							font-size: 22upx;
							color: #f6501f;
							border: 1upx solid #f6501f;
							padding: 5upx 10upx;
							border-radius: 10upx;
							margin-right: 10upx;
						}
					}
				}
				.salesNum{
					font-size: 24upx;
					color: #4d4d4d;
				}
			}
			.title{
				padding: 30upx;
				padding-top: 0;
				font-size: 28upx;
				color: #333;
				font-weight: bold;
			}
		}
		.severBox{
			background-color: #fff;
			margin-top: 20upx;
			box-sizing: border-box;
			padding-left: 30upx;
			>view{
				font-size: 24upx;
				padding: 28upx 0;
				color: #999;
				border-bottom: 1upx solid #f7f7f7;
				text{
					color: #333;
					margin-left: 30upx;
				}
				.express{
					padding-left: 20upx;
					border-left: 1upx solid #f7f7f7;
				}
				image{
					width: 22upx;
					height: 22upx;
				}
			}
			.param{
				display: flex;
				align-items: center;
				justify-content: space-between;
				box-sizing: border-box;
				padding-right: 28upx;
			}
		}	
		.evaluate{
			background-color: #fff;
			margin-top: 20upx;
			padding: 30upx 28upx;
			box-sizing: border-box;
			.title{
				color: #333;
				font-size: 28upx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding-bottom: 30upx;
				.readAll{
					font-size: 24upx;
					color: #b3b3b3;
					image{
						width: 22upx;
						height: 22upx;
						margin-left: 10upx;
					}
				}
			}
			.firstEvaluate{
				.userinfo{
					font-size: 22upx;
					color: #b3b3b3;
					display: flex;
					align-items: center;
					image{
					width: 28upx;
					height: 28upx;
					border-radius: 50%;
					margin-right: 10upx;
					margin-left: 8upx;
					}
				}
				.evaluateInfo{
					font-size: 24upx;
					color: #4d4d4d;
					font-weight: 500;
					padding-left: 45upx;
					display: -webkit-box;
					overflow: hidden;
					 white-space: normal!important;
					 text-overflow: ellipsis;
					 word-wrap: break-word;
					 -webkit-line-clamp: 2;
					 -webkit-box-orient: vertical;
				}
			}
		}
		.shop{
			background-color: #fff;
			margin-top: 20upx;
			padding: 30upx 28upx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			.shopName{
				display: flex;
				align-items: center;
				// justify-content: space-between;
				font-size: 28upx;
				color: #333;
				image{
					width: 88upx;
					height: 88upx;
					margin-right: 20upx;
				}
			}
			.goshop{
				background-color: #FF484A;
				width: 120upx;
				height: 44upx;
				border-radius: 22upx;
				font-size: 22upx;
				color: #fff;
				text-align: center;
				line-height: 44upx;
			}
		}
		.commodityInfo{
			background-color: #fff;
			margin-top: 20upx;
			margin-bottom: 120upx;
			.commodityHeader{
				text-align: center;
				font-size: 30upx;
				color: #333;
				border-bottom: 1upx solid #f2f2f2;
				padding-top: 40upx;
				padding-bottom: 20upx;
			}
			.commodityInfoContent{
				font-size: 0;
				text-align: center;
				background-color: #fff;
				image{
					width: 100%;
				}
			}
		}
		.bottom{
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			width: 100%;
			height: 100upx;
			color: #999;
			font-size: 0;
			background-color: #fff;
			>view{
				float: left;
				text-align: center;
				box-sizing: border-box;
			}
			image{
				width: 36upx;
				height: 36upx;
				margin-top: 15upx;
				
			}
			.kefu,.collect{
				width: 100upx;
				height: 100upx;
				font-size: 24upx;
				border-top: 1upx solid #f2f2f2;
				border-right: 1upx solid #f2f2f2;;
			}
			.btns{
				width: 275upx;	
				height: 100%;
				line-height: 100upx;
				font-size: 36upx;
				color: #fff;
				font-weight: bold;
			}
			.addCar{
				background-image: url('../../static/images/push_1.png');
				background-size: 100% 100%;
				
			}
			.buyNow{
				background-image: url('../../static/images/push_2.png');
				background-size: 100% 100%;
			}
		}
		
	}
</style>
